package com.yipei.business.controller;

import com.yipei.business.domain.MlImportantNews;
import com.yipei.business.service.IMlImportantNewsService;
import com.yipei.common.annotation.Log;
import com.yipei.common.core.controller.BaseController;
import com.yipei.common.core.domain.AjaxResult;
import com.yipei.common.core.page.TableDataInfo;
import com.yipei.common.enums.BusinessType;
import com.yipei.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 新闻要闻Controller
 *
 * @author yipei
 * @date 2024-12-21
 */
@RestController
@RequestMapping("/business/importantnews")
@Api(tags = "新闻要闻", description = "新闻要闻管理")
public class MlImportantNewsController extends BaseController {
    @Autowired
    private IMlImportantNewsService mlImportantNewsService;

    /**
     * 查询新闻要闻列表
     */
    //@PreAuthorize("@ss.hasPermi('business:importantnews:list')")
    @ApiOperation("新闻要闻获取数据")
    @GetMapping("/list")
    public TableDataInfo list(MlImportantNews mlImportantNews) throws IOException {
        startPage();
        List<MlImportantNews> list = mlImportantNewsService.selectMlImportantNewsList(mlImportantNews);
        return getDataTable(list);
    }

    /**
     * 导出新闻要闻列表
     */
    //@PreAuthorize("@ss.hasPermi('business:importantnews:export')")
    @ApiOperation("新闻要闻导出数据")
    @Log(title = "新闻要闻", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MlImportantNews mlImportantNews) {
        List<MlImportantNews> list = mlImportantNewsService.selectMlImportantNewsList(mlImportantNews);
        ExcelUtil<MlImportantNews> util = new ExcelUtil<MlImportantNews>(MlImportantNews.class);
        util.exportExcel(response, list, "新闻要闻数据");
    }

    /**
     * 获取新闻要闻详细信息
     */
    //@PreAuthorize("@ss.hasPermi('business:importantnews:query')")
    @ApiOperation("新闻要闻通过ID获取数据")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(mlImportantNewsService.selectMlImportantNewsById(id));
    }

    /**
     * 新增新闻要闻
     */
    //@PreAuthorize("@ss.hasPermi('business:importantnews:add')")
    @ApiOperation("新闻要闻新增数据")
    @Log(title = "新闻要闻", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MlImportantNews mlImportantNews) {
        return toAjax(mlImportantNewsService.insertMlImportantNews(mlImportantNews));
    }

    /**
     * 修改新闻要闻
     */
    //@PreAuthorize("@ss.hasPermi('business:importantnews:edit')")
    @ApiOperation("新闻要闻修改数据")
    @Log(title = "新闻要闻", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MlImportantNews mlImportantNews) {
        return toAjax(mlImportantNewsService.updateMlImportantNews(mlImportantNews));
    }

    /**
     * 删除新闻要闻
     */
    //@PreAuthorize("@ss.hasPermi('business:importantnews:remove')")
    @ApiOperation("新闻要闻删除数据")
    @Log(title = "新闻要闻", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mlImportantNewsService.deleteMlImportantNewsByIds(ids));
    }
}
